package com.shawn.model.vo;

import com.shawn.commons.utils.RC;
import com.shawn.model.entity.UserInfo;
import com.shawn.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommentsVo implements Serializable {
    private String id;//评论id
    private String avatar;//头像
    private Integer userId;
    private String nickname;//昵称
    private String content;//评论内容
    private String createDate;//评论时间
    private Integer likeCount;//点赞数
    private Integer hasLiked = 0;//todo 默认每条评论均未点赞 是否已点赞（1是，0否）根据用户id以及评论动态id查询出当前用户是否已经点赞

    //提供快速转换方法
    public static CommentsVo init(Comment comment, UserInfo userInfo) {
        CommentsVo commentsVo = new CommentsVo();
        BeanUtils.copyProperties(comment, commentsVo);
        commentsVo.setUserId(comment.getUserId().intValue());
        commentsVo.setId(comment.getId().toHexString());

        //转换评论时间
        commentsVo.setCreateDate(new SimpleDateFormat(RC.COMMENT_DATE_FORMAT).format(comment.getCreated()));
        BeanUtils.copyProperties(userInfo, commentsVo);
        return commentsVo;
    }
}